package com.miracle9.game.util;

import org.apache.log4j.Logger;

import java.util.HashMap;
import java.util.Map;

public class UserParticipateRecord {

    private static final Logger logger = Logger.getLogger(UserParticipateRecord.class);
    public static final int HALL = -1;
    public static final int ck = 100;
    public static final int cl = -2;
    public static final int cm = -3;
    public static final int cn = -4;
    private static Map<Integer, Integer> co = new HashMap<>();
    private static Map<Integer, Integer> cp = new HashMap<>();
    private static Map<Integer, Integer> cq = new HashMap<>();
    private static Map<Integer, SeatRecord> cr = new HashMap<>();
    private static Map<Integer, Integer> cs = new HashMap<>();

    public static void updateStatus(int userId, int status) {
        co.put(userId, status);
    }

    public static int checkUserId_1(int userId) {
        if (co.get(userId) == null) {
            return -1;
        }
        return co.get(userId);
    }

    public static void addUserStatusMapCQ(int userId, int status) {
        cq.put(userId, status);
    }

    public static int checkUserId_2(int userId) {
        if (cq.get(userId) == null) {
            return -2;
        }
        return cq.get(userId);
    }

    public static void removeUserIdMapCQ(int userId) {
        cq.remove(userId);
    }

    public static void addUserStatusMapCP(int userId, int status) {
        cp.put(userId, status);
    }

    public static int checkUserId_3(int userId) {
        if (cp.get(userId) == null) {
            return -3;
        }
        return cp.get(userId);
    }

    public static void removeUserIdMapCP(int userId) {
        cp.remove(userId);
    }

    public static boolean deskRecord(int userId, int deskId) {
        SeatRecord seatRecord = cr.get(userId);
        if (seatRecord == null) {
            seatRecord = new SeatRecord();
            seatRecord.setUserId(userId);
            seatRecord.k(deskId);
            seatRecord.getsitTime(System.currentTimeMillis());
            seatRecord.l(1);
            cr.put(userId, seatRecord);
        } else if (deskId == seatRecord.h()) {
            seatRecord.l(seatRecord.j() + 1);
        } else {
            seatRecord.k(deskId);
            seatRecord.getsitTime(System.currentTimeMillis());
            seatRecord.l(1);
        }
        if ((System.currentTimeMillis() - seatRecord.i() < 60000L) && (seatRecord.j() >= 30)) {
            return false;
        }
        if (System.currentTimeMillis() - seatRecord.i() > 60000L) {
            seatRecord.getsitTime(System.currentTimeMillis());
            seatRecord.l(1);
        }
        return true;
    }

    public static void removeUserIdMapCR(int userId) {
        cr.remove(userId);
    }

    public static int checkUserId_4(int userId) {
        if (cs.get(userId) == null) {
            return -4;
        }
        return cs.get(userId);
    }

    public static void removeUserIdMapCS(int userId) {
        cs.remove(userId);
    }

    public static void addUserGameMap(int userId, int game) {
        cs.put(userId, game);
    }

    public static void initialize() {
        co.clear();
        cp.clear();
        cq.clear();
        cr.clear();
        cs.clear();
    }

}
